package com.ai.bitcoin.exception;

import com.ai.bitcoin.common.resp.ResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: ${description}
 * @author: gulj
 * @create: 2018-07-07 18:13
 **/
@ControllerAdvice
@Slf4j
public class GlabalHandleException {


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseEntity handleException(Exception e) {
        log.error("【 Exception 】 {}",e);
        return new ResponseEntity(-1, e.getMessage());
    }


    @ResponseBody
    @ExceptionHandler(BussinessRuntimeException.class)
    public ResponseEntity handleBussinessRuntimeException(BussinessRuntimeException e) {
        log.info("【 BussinessRuntimeException 】，code = {}, message = {}", e.getCode(), e.getMsg());
        return new ResponseEntity(e.getCode(), e.getMsg());
    }

    @ResponseBody
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseEntity handle(MethodArgumentNotValidException e) {
        log.info("【 MethodArgumentNotValidException 】，message = {}", e.getMessage());
        return new ResponseEntity(-1, "参数不合法");
    }


}
